package isec.amov.tp2.automaintenance;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;

public class DbHelper extends SQLiteOpenHelper{
	
	//Static members
	public static final String DATABASE_NAME = "carro.db";
	public static final int DATABASE_VERSION = 1;
	public static final String ID ="id";
	public static final String MARCA ="marca";
	public static final String MODELO ="modelo";
	public static final String MATRICULA ="matricula";
	public static final String QUILOMETROS ="quilometros";
	public static final String TIPO ="tipo";
	public static final String ANO ="ano";
	public static final String MES ="mes";
	public static final String DIA ="dia";
	public static final String TABLE_NAME1 ="carro";
	public static final String TABLE_NAME2 ="detalhes";
	public static final String DB_PATH = "/data/data/isec.amov.tp2.automaintenance/databases/";
	private static final String DATABASE_CREATE1 = "create table "
			+ TABLE_NAME1 + " ( " 
			+ ID + " integer primary key autoincrement, " 
			+ MARCA + " text not null, " 
			+ MODELO + " text not null, "
			+ MATRICULA + " text not null, "
			+ QUILOMETROS +" text not null);";
	private static final String DATABASE_CREATE2 = "create table "
			+ TABLE_NAME2 + " ( " 
			+ ID + " integer primary key autoincrement, " 
			+ TIPO + " text not null, " 
			+ ANO + " text not null, "
			+ MES + " text not null, "
			+ DIA + " text not null, "
			+ QUILOMETROS +" text not null);";
	
	 
	//Constructor
	public DbHelper(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);
	}
	
    public DbHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    //Creates DB
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(DATABASE_CREATE1);
		//db.execSQL(DATABASE_CREATE2);
	}

	//Updates DB
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME1);
        //db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME2);
        onCreate(db); 
	}
}